﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace HippoScript
{
    public class AssemblyResolve
    {
        private static EvaluatorBase eveluator;
        public static EvaluatorBase Eveluator
        {
            get { return AssemblyResolve.eveluator; }
            set { AssemblyResolve.eveluator = value; }
        }
        public static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            //根据 args.Name 加载assembly
            //此处不会影响性能，仅在运行时加载一次
            string strFielName = args.Name.Split(',')[0];
            foreach (string refa in eveluator.ScriptContext.RefAssemblies)
            {
                if (refa.Contains(strFielName))
                {
                    return Assembly.LoadFile(refa);
                }
            }
            string sources = eveluator.BuildUPSource("");
            Assembly assembly = eveluator.CompileCode(sources, out eveluator._evaluatorObj, out eveluator._evaluatorType);
            return assembly;
        }
    }
}
